package org.micode.demo.db.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.micode.common.validater.InsertGroup;
import org.micode.common.validater.UpdateGroup;
import org.micode.common.validater.EnumValidation;
import org.micode.common.exception.VerifyFailException;
import org.micode.common.utils.StringExtUtils;
import org.micode.common.domain.base.entity.BaseDelUpdEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 角色信息实体类
 *
 * @author: wutianbin
 * @version: v1.0.27
 * @CreateDate: 2021-11-10
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysRoleDO extends BaseDelUpdEntity<Long> {

    /** 角色ID，Long */
    @NotNull(message = "角色ID,不能为空", groups = UpdateGroup.class)
    @PositiveOrZero(message = "角色ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long roleId;

    /** 角色名称，String */
    @NotNull(message = "角色名称,不能为空", groups = InsertGroup.class)
    @Size(max = 64,message = "角色名称,最大长度64个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String roleName;

    /** 默认标识, 枚举类型: DefaultFlagEnum，Integer */
    private Integer defaultFlag;

    /** 排序号，Integer */
    private Integer sortNo;

    /** 禁用标识, 枚举类型: DisableFlagEnum，Integer */
    private Integer disableFlag;

    /** 备注说明，String */
    @Size(max = 512,message = "备注说明,最大长度512个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String description;

    @JsonIgnore
    @Override
    public Long getKeyValue() {
        return roleId;
    }

    @Override
    public void checkBeforeInsert() {
        if (StringExtUtils.isAnyEmpty(roleName)) {
            throw new VerifyFailException("SysRoleDO.roleName 必须非空");
        }
    }

    @Override
    public String toString() {
        return "roleId=" + roleId +
                ", roleName='" + roleName + "'" +
                ", defaultFlag=" + defaultFlag +
                ", sortNo=" + sortNo +
                ", disableFlag=" + disableFlag +
                ", description='" + description + "'" +
                ", " + super.toString();
    }

}
